package com.wyp168.leetcode;

/**
 * @ClassName MaxArea
 * @Description TODO
 * @Author wyp168
 * @Date 2022/6/28 18:15
 */
public class MaxArea {
    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {

        int start = 0;
        int end = height.length - 1;
        int maxArea = 0;
        while (start != end) {
            int area = Math.min(height[start] , height[end]) * (end - start);
            if (maxArea < area)
                maxArea = area;

            if (height[start] > height[end])
                end --;
            else
                start ++;
        }
        return maxArea;
    }
}
